package com.tianhui.consignortwofei.mvp.ui.activity.deliverGoods.lite;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.amap.api.services.core.AMapException;
import com.amap.api.services.core.LatLonPoint;
import com.amap.api.services.core.ServiceSettings;
import com.amap.api.services.geocoder.GeocodeAddress;
import com.amap.api.services.geocoder.GeocodeQuery;
import com.amap.api.services.geocoder.GeocodeResult;
import com.amap.api.services.geocoder.GeocodeSearch;
import com.amap.api.services.geocoder.RegeocodeResult;
import com.amap.api.services.route.DistanceItem;
import com.amap.api.services.route.DistanceResult;
import com.amap.api.services.route.DistanceSearch;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.search.sug.SuggestionResult;
import com.baidu.mapapi.search.sug.SuggestionSearch;
import com.fgs.common.CommonFragment;
import com.fgs.common.CommonResponse;
import com.fgs.common.entity.SelectItemInfo;
import com.fgs.common.entity.region.RegionInfo;
import com.fgs.common.progress.ExceptionHandle;
import com.fgs.common.progress.ObserverResponseListener;
import com.fgs.common.utils.CommonUtil;
import com.fgs.common.utils.DateUtil;
import com.fgs.common.utils.LogUtil;
import com.fgs.common.utils.ToastUtil;
import com.fgs.common.widget.SelectDialog;
import com.fgs.common.widget.TabSwitchView;
import com.fgs.common.widget.itemView.CitySearchView;
import com.fgs.common.widget.itemView.ClickItemView;
import com.fgs.common.widget.itemView.InputItemView;
import com.google.gson.Gson;
import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.constant.KeyValue;
import com.tianhui.consignortwofei.interf.impl.LoadingSelectTimeData;
import com.tianhui.consignortwofei.manager.SharedPreferenceManager;
import com.tianhui.consignortwofei.mvp.contract.GoodsContract;
import com.tianhui.consignortwofei.mvp.model.FindCarDeliveryInfo;
import com.tianhui.consignortwofei.mvp.model.GoodsModel;
import com.tianhui.consignortwofei.mvp.model.OrderModel;
import com.tianhui.consignortwofei.mvp.model.enty.DictionaryInfo;
import com.tianhui.consignortwofei.mvp.model.enty.DispatcherInfo;
import com.tianhui.consignortwofei.mvp.model.enty.GoodsInfo;
import com.tianhui.consignortwofei.mvp.model.enty.SourcePathInfo;
import com.tianhui.consignortwofei.mvp.model.enty.VehicleLimitInfo;
import com.tianhui.consignortwofei.mvp.presenter.GoodsPresenter;
import com.tianhui.consignortwofei.mvp.ui.activity.DriverDetailListActivity;
import com.tianhui.consignortwofei.mvp.ui.activity.SalesManListActivity;
import com.tianhui.consignortwofei.mvp.ui.activity.SelectDressActivity;

import com.tianhui.consignortwofei.mvp.ui.activity.SourcePathListActivity;
import com.tianhui.consignortwofei.mvp.ui.activity.deliverGoods.BaseDeliverGoodsActivity;
import com.tianhui.consignortwofei.mvp.ui.activity.deliverGoods.DeliverGoodsSuccessActivity;
import com.tianhui.consignortwofei.mvp.ui.adapter.PopDressListAdapter;
import com.tianhui.consignortwofei.utils.ApplicationUtil;
import com.tianhui.consignortwofei.widget.SelectTimeDialog;
import com.xuexiang.xui.widget.dialog.materialdialog.DialogAction;
import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.yczbj.ycrefreshviewlib.inter.OnItemClickListener;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author 发找车单
 * @date 2021/6/18
 * @description
 **/
public class FindCarLiteDeliverActivity extends BaseDeliverGoodsActivity {
    private static final int REQUEST_CODE_HISTORY = 1001;
    private static final int REQUEST_CODE_SALES_MAN = 1002;
    private static final int REQUEST_CODE_DRIVER_DETAIL = 1003;
    @BindView(R.id.activity_lite_deliver_goods_deliverSourcePathLinearLayout)
    LinearLayout mDeliverSourcePathLinearLayout;
    @BindView(R.id.activity_lite_deliver_goods_destinationSourcePathLinearLayout)
    LinearLayout mDestinationSourcePathLinearLayout;

    @BindView(R.id.activity_lite_deliver_goods_goodsTypeClickItemView)
    protected ClickItemView mGoodsTypeClickItemView;


//    @BindView(R.id.activity_lite_deliver_goods_goodsNameInputItemView)
//    protected InputItemView mGoodsNameInputItemView;
    @BindView(R.id.activity_lite_deliver_goods_weightInputItemView)
    protected InputItemView mWeightInputItemView;
//    @BindView(R.id.activity_lite_deliver_goods_detachableTabSwitchView)
//    protected TabSwitchView mDetachableTabSwitchView;
//    @BindView(R.id.activity_lite_deliver_goods_detachWeightLinearLayout)
//    protected LinearLayout mDetachWeightLinearLayout;
//    @BindView(R.id.activity_lite_deliver_goods_detachWeightInputItem)
//    protected InputItemView mDetachWeightInputItemView;
//    @BindView(R.id.activity_lite_deliver_goods_priceLinearLayout)
//    protected LinearLayout mPriceLinearLayout;
//    @BindView(R.id.activity_lite_deliver_goods_priceInputItemView)
//    protected InputItemView mPriceInputItemView;
//    @BindView(R.id.activity_lite_deliver_goods_maxPriceInputItemView)
//    protected InputItemView mMaxPriceInputItemView;
//    @BindView(R.id.inputv_zong_two)
//    protected InputItemView inputv_zong_two;
//    @BindView(R.id.activity_lite_deliver_goods_totalPriceInputItemView)
//    protected InputItemView mTotalPriceInputItemView;
//    @BindView(R.id.activity_lite_deliver_goods_priceStatusTabSwitchView)
//    protected TabSwitchView mPriceStatusTabSwitchView;
//    @BindView(R.id.activity_lite_deliver_goods_phoneLinearLayout)
//    protected LinearLayout mPhoneLinearLayout;
//    @BindView(R.id.activity_lite_deliver_goods_phoneInputItemView)
//    protected InputItemView mPhoneInputItemView;
    @BindView(R.id.activity_lite_deliver_goods_pushableTabSwitchView)
    protected TabSwitchView mPushableTabSwitchView;
    @BindView(R.id.activity_lite_deliver_goods_goodsPriceInputItemView)
    protected InputItemView mGoodsPriceInputItemView;
    @BindView(R.id.activity_lite_deliver_goods_deadlineTimeClickItemView)
    protected ClickItemView mDeadlineTimeClickItemView;
    @BindView(R.id.activity_lite_deliver_goods_earliestTimeClickItemView)
    protected ClickItemView mEarliestTimeClickItemView;
    @BindView(R.id.activity_lite_deliver_goods_deliverTimeInputItemView)
    protected InputItemView mDeliverTimeInputItemView;
    @BindView(R.id.activity_lite_deliver_goods_vehicleLimitClickItemView)
    protected ClickItemView mVehicleLimitClickItemView;
    @BindView(R.id.activity_lite_deliver_goods_businessLinearLayout)
    protected LinearLayout mBusinessLinearLayout;
    @BindView(R.id.activity_lite_deliver_goods_remarkInputItemView)
    protected InputItemView mRemarkInputItemView;
    @BindView(R.id.activity_lite_deliver_goods_businessNumberInputItemView)
    protected InputItemView mBusinessNumberInputItemView;
    @BindView(R.id.activity_lite_deliver_goods_cargoRightsClickItemView)
    protected ClickItemView mCargoRightsClickItemView;
    @BindView(R.id.activity_lite_deliver_goods_dispatcherClickItemView)
    protected ClickItemView mDispatcherClickItemView;
    @BindView(R.id.activity_lite_deliver_goods_salesManListLinearLayout)
    protected LinearLayout mSalesManListLinearLayout;
    @BindView(R.id.activity_lite_deliver_goods_salesManListClickItemView)
    protected ClickItemView mSalesManListClickItemView;
    @BindView(R.id.activity_lite_deliver_goods_belongAreaLinearLayout)
    protected LinearLayout mBelongAreaLinearLayout;
    @BindView(R.id.activity_lite_deliver_goods_belongAreaClickItemView)
    protected ClickItemView mBelongAreaClickItemView;

    @BindView(R.id.activity_lite_deliver_goods_sendObjectClickItemView)
    protected ClickItemView mSendObjectClickItemView;
    @BindView(R.id.activity_lite_deliver_goods_objectDetailLinearLayout)
    protected LinearLayout mObjectDetailLinearLayout;
    @BindView(R.id.activity_lite_deliver_goods_objectDetailClickItemView)
    protected ClickItemView mObjectDetailClickItemView;
    @BindView(R.id.iiv_kehu)
    protected InputItemView iiv_kehu;

    //部门
//    @BindView(R.id.civ_bumen)
//    protected ClickItemView civ_bumen;


    private SelectDialog mVehicleLimitSelectDialog;
    private SelectDialog mDispatcherListSelectDialog;
    private SelectDialog mSendObjectSelectDialog;

    private SelectDialog mGoodsTypeSelectDialog;
    private SelectDialog mCargoRightsSelectDialog;
    private SelectDialog mBelongAreaSelectDialog;
    private SelectTimeDialog mDeadlineSelectTimeDialog;
    private String mGoodsWeight;
    private String mPrice;
    private String allPrice;



    protected ClickItemView  zhuang_dizhi_two ;
    protected ClickItemView xie_dizhi_two ;


    protected ClickItemView zhuang_dress_two ;
    protected ClickItemView  xie_dress_two;


    protected CitySearchView mDeliverCitySearchView;
    protected CitySearchView mDestinationCitySearchView;

    private TextView mDeliverHistoryTextView;
    private TextView mDestinationHistoryTextView;

    private TextView mDeliverSaveTextView;
    private TextView mDestinationSaveTextView;

    protected InputItemView mDeliverUserInputItemView;
    protected InputItemView mDestinationUserInputItemView;

    protected InputItemView mDeliverAddressInputItemView;
    protected InputItemView mDestinationAddressInputItemView;


    protected InputItemView mDeliverPhoneInputItemView;
    protected InputItemView mDestinationPhoneInputItemView;


    //销售员时，需要显示的信息
    private boolean isShowBusinessView;
    //显示选择销售员View
    private boolean isShowSalesManView;
    //显示选择所属区域
    private boolean isShowBelongArea;
    private boolean isNeedReprocessingPathInfo;

    private boolean xunHuanDan=true;
    private boolean xunHuanZong=true;

    //发票
//    @BindView(R.id.fapioa_item_contentEditText)
//    protected TextView fapioa_item_contentEditText;
//    @BindView(R.id.fapiao_layout_body)
//    protected View fapiao_layout_body;
//    @BindView(R.id.et_fapiao_num)
//    protected EditText et_fapiao_num;
//    @BindView(R.id.rb_tui)
//    protected RadioButton rb_tui;
//    @BindView(R.id.rb_butui)
//    protected RadioButton rb_butui;
//    @BindView(R.id.fapiao_jine_body)
//    protected View fapiao_jine_body;

    @BindView(R.id.itv_juli)
    protected InputItemView itv_juli;

    @BindView(R.id.iiv_cunhuo)
    protected InputItemView iiv_cunhuo;



    //是否退款
    private boolean isFaPiaoTuiHuan=true;
    private SelectDialog mFaPiaoDialog;
    private SuggestionSearch mSuggestionSearch;

    //找车单属性
    private FindCarDeliveryInfo.CarRecords carRecords;
    private FrameLayout saveItemOne;
    private FrameLayout saveItemTwo;
    private GoodsModel mModel;
    private String erpWeight="0";

    @Override
    public String getToolbarTitle() {
        return "找车单";
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_findcar_lite_deliver;
    }

    @Override
    public GoodsPresenter createPresenter() {
        return new GoodsPresenter();
    }

    @Override
    public GoodsContract.View createView() {
        return this;
    }

    @Override
    public CommonFragment createFragment() {
        return null;
    }

    @Override
    public void initData() {
        mGoodsInfo.ishide = "0";
        mGoodsInfo.detachable = "0";

        mGoodsInfo.isstate = 1;
        mGoodsInfo.quotation = "0";
        mGoodsInfo.isdelegateshipment = "1";
        mGoodsInfo.vehiclelengthtype = "";
        mGoodsInfo.ispush = "1";
        mGoodsInfo.billsource = "2";
        mGoodsInfo.sentto = "00";

        mGoodsInfo.senddistance = "0";//相距公里数
        mGoodsInfo.quantity = "0";
        mGoodsInfo.isdelegateshipment = "1";
        mGoodsInfo.isinsure = "0";
        mGoodsInfo.insureprice = "0";
        mGoodsInfo.schemeCode = "";
        mGoodsInfo.consumequota = "0";
        mGoodsInfo.consumefixedrate = "0";
        mGoodsInfo.belongarea = "2";

        String consignor = SharedPreferenceManager.getInstance().getConsignorName();
        mGoodsInfo.clientperson = consignor;
        mGoodsInfo.clienttel = SharedPreferenceManager.getInstance().getPhone();

//        isShowBusinessView = RoleController.getInstance().isShowBusinessView();
//        isShowSalesManView = RoleController.getInstance().isShowSalesMan();
//        isShowBelongArea = RoleController.getInstance().isShowBelongArea();

        Bundle bundle = getIntent().getExtras();
        String erpdetails = bundle.getString("erpdetails");
        Gson gson=new Gson();
        carRecords = gson.fromJson(erpdetails, FindCarDeliveryInfo.CarRecords.class);
        mGoodsInfo.code=carRecords.getCode();
        mGoodsInfo.hq=carRecords.getHq();
        mGoodsInfo.inventoryname=carRecords.getInventoryname();
        mGoodsInfo.inventorycode=carRecords.getInventorycode();
        mGoodsInfo.voucherdate=carRecords.getVoucherdate();
        mGoodsInfo.quantity=carRecords.getQuantity();
        mGoodsInfo.dyf=carRecords.getDyf();
        mGoodsInfo.dzcf=carRecords.getDzcf();
        mGoodsInfo.dccf=carRecords.getDccf();
        mGoodsInfo.qtf=carRecords.getQtf();
        mGoodsInfo.housename=carRecords.getHousename();
        mGoodsInfo.address=carRecords.getAddress();
        mGoodsInfo.memo=carRecords.getMemo();
        mGoodsInfo.cd=carRecords.getCd();
        mGoodsInfo.partnername=carRecords.getPartnername();
        mGoodsInfo.codeid=carRecords.getID();

        //地址选择pop
//        allSuggestions=new ArrayList<>();
//        mSuggestionSearch = SuggestionSearch.newInstance();
//        OnGetSuggestionResultListener listener = new OnGetSuggestionResultListener() {
//            @Override
//            public void onGetSuggestionResult(SuggestionResult suggestionResult) {
//                //处理sug检索结果
//                allSuggestions.clear();
//                allSuggestions.addAll(suggestionResult.getAllSuggestions());
//                dressListAdapter.removeAll();
//                dressListAdapter.addAll(allSuggestions);
//
////                int offsetX = mDeliverAddressInputItemView.getWidth() - dressPopup.getContentView().getMeasuredWidth();
//                if (1==whitchSet) {
//                    PopupWindowCompat.showAsDropDown(dressPopup,mDeliverAddressInputItemView,0,0,Gravity.BOTTOM);
//                }else {
//                    PopupWindowCompat.showAsDropDown(dressPopup,mDestinationAddressInputItemView,0,0,Gravity.BOTTOM);
//                }
//
//
//            }
//        };
//        mSuggestionSearch.setOnGetSuggestionResultListener(listener);

//        EventBus.getDefault().register(this);

         pathInfoZhuang=new SourcePathInfo();
         pathInfoXie=new SourcePathInfo();
    }


    @Override
    public void initView() {

        mVehicleLimitClickItemView.setContent("车长不限");
        mDeadlineTimeClickItemView.setContent(getTomorrowDate());
        mEarliestTimeClickItemView.setContent(getTomorrowDate());
        mDeliverTimeInputItemView.setContent("1");
        mBelongAreaClickItemView.setContent("天津");
        mSendObjectClickItemView.setContent("全部");

        //发票
//        et_fapiao_num.setText("0");

        //找车单属性填入
        try {
            String quantity = mGoodsInfo.quantity;
            if (!TextUtils.isEmpty(quantity)) {
                Double aDouble = Double.valueOf(quantity);
                String result = String.format("%.3f",aDouble);
                String text = subZeroAndDot(result);
                mWeightInputItemView.setContent(text);
                mGoodsInfo.weight=text;
                erpWeight=text;
            }
        }catch (Exception e){
            LogUtil.print("fei",e.toString());
        }
//        mPriceInputItemView.setContent(mGoodsInfo.dyf);
        setZhuanhuo(mGoodsInfo.address,"");

//        setZhuanhuo("天津市滨海新区通达源物流配送公司","");


        zhuang_dizhi_two = mDeliverSourcePathLinearLayout.findViewById(R.id.citv_dizhi_two);
        xie_dizhi_two = mDestinationSourcePathLinearLayout.findViewById(R.id.citv_dizhi_two);


        zhuang_dress_two = mDeliverSourcePathLinearLayout.findViewById(R.id.citv_dress_two);
        xie_dress_two = mDestinationSourcePathLinearLayout.findViewById(R.id.citv_dress_two);


        mDeliverCitySearchView = mDeliverSourcePathLinearLayout.findViewById(R.id.layout_deliver_source_path_sourcePathCitySearchView);
        mDestinationCitySearchView = mDestinationSourcePathLinearLayout.findViewById(R.id.layout_deliver_source_path_sourcePathCitySearchView);


        mDeliverHistoryTextView = mDeliverSourcePathLinearLayout.findViewById(R.id.layout_deliver_source_path_historyTextView);
        mDestinationHistoryTextView = mDestinationSourcePathLinearLayout.findViewById(R.id.layout_deliver_source_path_historyTextView);

        mDeliverSaveTextView = mDeliverSourcePathLinearLayout.findViewById(R.id.layout_deliver_source_path_saveTextView);
        mDestinationSaveTextView = mDestinationSourcePathLinearLayout.findViewById(R.id.layout_deliver_source_path_saveTextView);

        mDeliverUserInputItemView = mDeliverSourcePathLinearLayout.findViewById(R.id.layout_deliver_source_path_userInputItemView);
        mDestinationUserInputItemView = mDestinationSourcePathLinearLayout.findViewById(R.id.layout_deliver_source_path_userInputItemView);


        mDeliverAddressInputItemView = mDeliverSourcePathLinearLayout.findViewById(R.id.layout_deliver_source_path_addressInputItemView);
        mDestinationAddressInputItemView = mDestinationSourcePathLinearLayout.findViewById(R.id.layout_deliver_source_path_addressInputItemView);

        saveItemOne = mDeliverSourcePathLinearLayout.findViewById(R.id.fl_save_item);
        saveItemTwo = mDestinationSourcePathLinearLayout.findViewById(R.id.fl_save_item);

        mDeliverPhoneInputItemView = mDeliverSourcePathLinearLayout.findViewById(R.id.layout_deliver_source_path_phoneInputItemView);
        mDestinationPhoneInputItemView = mDestinationSourcePathLinearLayout.findViewById(R.id.layout_deliver_source_path_phoneInputItemView);

        mDeliverCitySearchView.setTitle("装货地");
        mDeliverCitySearchView.setContentHint("请输入或选择装货地");
        mDestinationCitySearchView.setTitle("目的地");
        mDestinationCitySearchView.setContentHint("请输入或选择目的地");

        mDeliverUserInputItemView.setTitle("装货人");
        String consignorName = SharedPreferenceManager.getInstance().getConsignorName();
        mDeliverUserInputItemView.setContent(consignorName);
        mDestinationUserInputItemView.setTitle("收货人");
        mGoodsPriceInputItemView.setContent("10000");

        iiv_cunhuo.setContent(mGoodsInfo.inventoryname);

        //========新增地址跳转
        zhuang_dizhi_two.setVisibility(View.VISIBLE);
        zhuang_dress_two.setVisibility(View.VISIBLE);
        zhuang_dizhi_two.setTitle("装货地");
        zhuang_dizhi_two.setContentHint("请输入或选择装货地");

        xie_dizhi_two.setVisibility(View.VISIBLE);
        xie_dress_two.setVisibility(View.VISIBLE);
        xie_dizhi_two.setTitle("目的地");
        xie_dizhi_two.setContentHint("请输入或选择目的地");

        mDestinationCitySearchView.setVisibility(View.GONE);
        mDestinationAddressInputItemView.setVisibility(View.GONE);
        mDeliverCitySearchView.setVisibility(View.GONE);
        mDeliverAddressInputItemView.setVisibility(View.GONE);
        saveItemOne .setVisibility(View.GONE);
        saveItemTwo.setVisibility(View.GONE);

        //默认货主手机号
        String phone = SharedPreferenceManager.getInstance().getPhone();
        mDeliverPhoneInputItemView.setContent(phone);

//        mDestinationUserInputItemView.setContent(SharedPreferenceManager.getInstance().getConsignorName());
//        mDestinationPhoneInputItemView.setContent(SharedPreferenceManager.getInstance().getPhone());

//        isShowBusinessView(isShowBusinessView);
//        isShowSalesManView(isShowSalesManView);//销售员
//        isShowBelongAreaView(isShowBelongArea);

        mWeightInputItemView.getEditTextView().setSelectAllOnFocus(true);
        iiv_kehu.setVisibility(View.VISIBLE);
        iiv_kehu.setContent(mGoodsInfo.partnername);

        mModel = new GoodsModel();

        setJiaGe();

        //货物类型
        getLeiXingList();


//        initPopupWindow();
    }

    //所属区域
    private void isShowBelongAreaView(boolean isShow) {
//        if (isShow) {
//            mBelongAreaLinearLayout.setVisibility(View.VISIBLE);
//        } else {
//            mBelongAreaLinearLayout.setVisibility(View.GONE);
//        }
    }


    //
    private void isShowSalesManView(boolean isShow) {
        if (isShow) {
            mSalesManListLinearLayout.setVisibility(View.VISIBLE);
        } else {
            mSalesManListLinearLayout.setVisibility(View.GONE);
        }
    }

    private void isShowBusinessView(boolean isShow) {
        if (isShow) {
            mBusinessLinearLayout.setVisibility(View.VISIBLE);
        } else {
            mBusinessLinearLayout.setVisibility(View.GONE);
        }
    }

    private String getTomorrowDate() {
        return DateUtil.getTomorrowDate("yyyy-MM-dd HH:mm:ss");
    }

    @Override
    public void initListener() {
        mDeliverCitySearchView.setOnCitySearchListener(new CitySearchView.OnCitySearchListener() {
            @Override
            public void citySearchCallback(RegionInfo regionInfo) {
                SourcePathInfo sourcePathInfo = new SourcePathInfo();
                sourcePathInfo.placeprovince = regionInfo.province;
                sourcePathInfo.placecity = regionInfo.city;
                sourcePathInfo.placecounty = regionInfo.county;
                sourcePathInfo.placecitycode = regionInfo.code;
                sourcePathInfo.placeparentcode = regionInfo.parentcode;
                setSelectPathInfo(KeyValue.RESULT_DELIVER, sourcePathInfo, true);

            }
        });

        mDeliverCitySearchView.setOnCitySearchSelectListener(new CitySearchView.OnCitySearchSelectListener() {
            @Override
            public void onCitySelect(RegionInfo regionInfo) {
                SourcePathInfo sourcePathInfo = new SourcePathInfo();
                sourcePathInfo.placeprovince = regionInfo.province;
                sourcePathInfo.placecity = regionInfo.city;
                sourcePathInfo.placecounty = regionInfo.county;
                sourcePathInfo.placecitycode = regionInfo.code;
                sourcePathInfo.placeparentcode = regionInfo.parentcode;
                setSelectPathInfo(KeyValue.RESULT_DELIVER, sourcePathInfo, false);
            }
        });

        mDestinationCitySearchView.setOnCitySearchListener(new CitySearchView.OnCitySearchListener() {
            @Override
            public void citySearchCallback(RegionInfo regionInfo) {
                SourcePathInfo sourcePathInfo = new SourcePathInfo();
                sourcePathInfo.placeprovince = regionInfo.province;
                sourcePathInfo.placecity = regionInfo.city;
                sourcePathInfo.placecounty = regionInfo.county;
                sourcePathInfo.placecitycode = regionInfo.code;
                sourcePathInfo.placeparentcode = regionInfo.parentcode;
                setSelectPathInfo(KeyValue.RESULT_DESTINATION, sourcePathInfo, true);
            }
        });

        mDestinationCitySearchView.setOnCitySearchSelectListener(new CitySearchView.OnCitySearchSelectListener() {
            @Override
            public void onCitySelect(RegionInfo regionInfo) {
                SourcePathInfo sourcePathInfo = new SourcePathInfo();
                sourcePathInfo.placeprovince = regionInfo.province;
                sourcePathInfo.placecity = regionInfo.city;
                sourcePathInfo.placecounty = regionInfo.county;
                sourcePathInfo.placecitycode = regionInfo.code;
                sourcePathInfo.placeparentcode = regionInfo.parentcode;
                setSelectPathInfo(KeyValue.RESULT_DESTINATION, sourcePathInfo, false);
            }
        });


        mDeliverHistoryTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putInt(KeyValue.KEY_TYPE, KeyValue.RESULT_DELIVER);
                openActivityForResult(REQUEST_CODE_HISTORY, SourcePathListActivity.class, bundle);
            }
        });
        mDestinationHistoryTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putInt(KeyValue.KEY_TYPE, KeyValue.RESULT_DESTINATION);
                openActivityForResult(REQUEST_CODE_HISTORY, SourcePathListActivity.class, bundle);
            }
        });

        mDeliverSaveTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mGoodsInfo != null) {
                    String details = mDeliverAddressInputItemView.getContent();
                    String placeTel = mDeliverPhoneInputItemView.getContent();
                    String placeUserName = mDeliverUserInputItemView.getContent();

                    mGoodsInfo.deliverdetails = details;
                    mGoodsInfo.delivertel = placeTel;
                    mGoodsInfo.deliverusername = placeUserName;
                    getPresenter().requestDeliverPathSave(mGoodsInfo);
                }
            }
        });

        mDestinationSaveTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mGoodsInfo != null) {
                    String details = mDestinationAddressInputItemView.getContent();
                    String placeTel = mDestinationPhoneInputItemView.getContent();
                    String placeUserName = mDestinationUserInputItemView.getContent();

                    mGoodsInfo.destinationdetails = details;
                    mGoodsInfo.destinationtel = placeTel;
                    mGoodsInfo.destinationusername = placeUserName;
                    getPresenter().requestDestinationPathSave(mGoodsInfo);
                }
            }
        });


//        mPriceInputItemView.setOnInputItemListener(new InputItemView.OnInputItemListener() {
//            @Override
//            public void onInput(String string) {
////                if (xunHuanZong) {
////                    xunHuanZong=false;
//
//                    mPrice = string;
////                    handler.removeCallbacks(runnableDan);
////                    handler.postDelayed(runnableDan, 2000);
//                    mMaxPriceInputItemView.setContent(string);
//                    mTotalPriceInputItemView.setContent(getTotalPrice());
////                    xunHuan=true;
////                }
//            }
//        });
//
//
//        inputv_zong_two.setOnInputItemListener(new InputItemView.OnInputItemListener() {
//            @Override
//            public void onInput(String string) {
//                allPrice = string;
//
//                String djPrice = getDJPrice();
//                mPriceInputItemView.setContent(djPrice);
//                mMaxPriceInputItemView.setContent(djPrice);
//
//            }
//        });




        zhuang_dizhi_two.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                goSelectDress(2);
            }
        });
        zhuang_dress_two.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                goSelectDress(2);
            }
        });

        xie_dizhi_two.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                goSelectDress(3);
            }
        });
        xie_dress_two.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                goSelectDress(3);
            }
        });

//        mTotalPriceInputItemView.setOnInputItemListener(new InputItemView.OnInputItemListener() {
//            @Override
//            public void onInput(String string) {
//                if (xunHuanDan) {
//                    xunHuanDan=false;
//                    allPrice = string;
//
//                    handler.removeCallbacks(runnableZong);
//                    handler.postDelayed(runnableZong, 2000);
//                    mPriceInputItemView.setContent(getDJPrice());
//                    mMaxPriceInputItemView.setContent(getDJPrice());
//
////                    xunHuan=true;
//                }
//            }
//        });

//        //装货详细地址
//        mDeliverAddressInputItemView.setOnInputItemListener(new InputItemView.OnInputItemListener() {
//            @Override
//            public void onInput(String string) {
//                if (openPop) {
//                    if (!TextUtils.isEmpty(string)) {
//                        whitchSet=1;
////                    } else {
//                        /**
//                         * 在您的项目中，keyword为随您的输入变化的值
//                         */
//                        mSuggestionSearch.requestSuggestion(new SuggestionSearchOption()
//                                .city("北京")
//                                .keyword("肯"));
//                    }
//                }else {
//                    openPop=true;
//                }
//
//            }
//        });
//
//        //卸货详细地址
//        mDestinationAddressInputItemView.setOnInputItemListener(new InputItemView.OnInputItemListener() {
//            @Override
//            public void onInput(String string) {
//                if (openPop) {
//                    if (!TextUtils.isEmpty(string)) {
//                        whitchSet=2;
////                    } else {
//                        /**
//                         * 在您的项目中，keyword为随您的输入变化的值
//                         */
//                        mSuggestionSearch.requestSuggestion(new SuggestionSearchOption()
//                                .city("北京")
//                                .keyword("肯"));
//                    }
//                }else {
//                    openPop=true;
//                }
//
//            }
//        });




        mWeightInputItemView.setOnInputItemListener(new InputItemView.OnInputItemListener() {
            @Override
            public void onInput(String string) {
                mGoodsWeight = string;
//                mTotalPriceInputItemView.setContent(getTotalPrice());
            }
        });
//        mPriceStatusTabSwitchView.setOnTabCheckedChangeListener(new TabSwitchView.OnTabCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(int position, String item, String value) {
//                mGoodsInfo.ishide = value;
//                showInquiryInfoView(position == 0);
//            }
//        });
//
//        //是否可拆单
//        mDetachableTabSwitchView.setOnTabCheckedChangeListener(new TabSwitchView.OnTabCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(int position, String item, String value) {
//                if (position == 0) {
//                    mDetachWeightLinearLayout.setVisibility(View.VISIBLE);
//                    mDetachWeightInputItemView.setContent("0");
//                } else {
//                    mGoodsInfo.detachweight = "";
//                    mDetachWeightLinearLayout.setVisibility(View.GONE);
//                }
//                mGoodsInfo.detachable = value;
//            }
//        });

        //是否推送
        mPushableTabSwitchView.setOnTabCheckedChangeListener(new TabSwitchView.OnTabCheckedChangeListener() {
            @Override
            public void onCheckedChanged(int position, String item, String value) {
                mGoodsInfo.ispush = value;
            }
        });




        //发票
//        fapiao_layout_body.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                popWindow();
//            }
//        });
//
//        rb_tui.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                isFaPiaoTuiHuan=true;
//
//            }
//        });
//
//        rb_butui.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                isFaPiaoTuiHuan=false;
//
//            }
//        });


    }



    //是否询价
    private void showInquiryInfoView(boolean isShow) {
//        if (isShow) {
//            mPhoneInputItemView.setContent(SharedPreferenceManager.getInstance().getPhone());
//            mPhoneLinearLayout.setVisibility(View.VISIBLE);
//            mPriceLinearLayout.setVisibility(View.GONE);
//        } else {
//            mPhoneInputItemView.setContent("");
//            mPhoneLinearLayout.setVisibility(View.GONE);
//            mPriceLinearLayout.setVisibility(View.VISIBLE);
//        }
    }

    private String getTotalPrice() {
        return mDataProcess.getTotalPrice(mPrice, mGoodsWeight);
    }


    private void setSelectPathInfo(int resultCode, SourcePathInfo pathInfo, boolean isNeedReprocessingPathInfo) {
        if (pathInfo == null) return;
        if (resultCode == KeyValue.RESULT_DELIVER) {
            mDataProcess.processPlaceSelectPathInfo(mGoodsInfo, pathInfo);
            mDataProcess.processDeliverySelectPathInfo(mGoodsInfo, pathInfo);
            mDeliverCitySearchView.setIsNeedFilterCity(isNeedReprocessingPathInfo);
            mDeliverCitySearchView.setContent(pathInfo.address);
        } else if (resultCode == KeyValue.RESULT_DESTINATION) {
            mDataProcess.processDestinationSelectPathInfo(mGoodsInfo, pathInfo);
            mDeliverCitySearchView.setIsNeedFilterCity(isNeedReprocessingPathInfo);
            mDestinationCitySearchView.setContent(pathInfo.address);
        }


    }

    //设置选择的历史路线信息
    protected void setSelectPathHistory(int resultCode,
                                        CitySearchView placeClickItemView,
                                        InputItemView placeAddressInputItemView,
                                        InputItemView placeUserInputItemView,
                                        InputItemView placePhoneInputItemView,
                                        SourcePathInfo sourcePathInfo,
                                        ClickItemView placeClickItemViewTwo,
                                        ClickItemView placeAddressInputItemViewTwo
    ) {
        if (sourcePathInfo == null) return;
        placeClickItemView.setContent(sourcePathInfo.address);
        placeAddressInputItemView.setContent(sourcePathInfo.placedetails);
        placeUserInputItemView.setContent(sourcePathInfo.placeusername);
        placePhoneInputItemView.setContent(sourcePathInfo.placetel);

        placeClickItemViewTwo.setContent(sourcePathInfo.address);
        placeAddressInputItemViewTwo.setContent(sourcePathInfo.placedetails);

        String placeDress = sourcePathInfo.address + sourcePathInfo.placedetails;
        String placeCity = sourcePathInfo.placecity;


//        getSaveJingWei("任丘市麻家务镇中学","沧州市",resultCode);
        getSaveJingWei(placeDress,placeCity,resultCode);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        SourcePathInfo pathInfo;
        if (requestCode == REQUEST_CODE && data != null) {
            pathInfo = data.getParcelableExtra(KeyValue.KEY_PATH_INFO);
            setSelectPathInfo(resultCode, pathInfo, false);
        } else if (requestCode == REQUEST_CODE_HISTORY && data != null) {
            pathInfo = data.getParcelableExtra(KeyValue.KEY_PATH_INFO);
            setSelectPathInfo(resultCode, pathInfo, false);
            if (resultCode == KeyValue.RESULT_DELIVER) {
                setSelectPathHistory(resultCode,mDeliverCitySearchView, mDeliverAddressInputItemView, mDeliverUserInputItemView, mDeliverPhoneInputItemView, pathInfo,zhuang_dizhi_two,zhuang_dress_two);
            } else if (resultCode == KeyValue.RESULT_DESTINATION) {
                setSelectPathHistory(resultCode,mDestinationCitySearchView, mDestinationAddressInputItemView, mDestinationUserInputItemView, mDestinationPhoneInputItemView, pathInfo,xie_dizhi_two,xie_dress_two);
            }

        } else if (requestCode == REQUEST_CODE_SALES_MAN && resultCode == KeyValue.KEY_RESULT_CODE) {

            setSelectSalesMan(data);
        } else if (requestCode == REQUEST_CODE_DRIVER_DETAIL && resultCode == KeyValue.KEY_RESULT_CODE) {
            setSelectDriver(data);
        }
    }

    //指定的司机
    private void setSelectDriver(Intent data) {
        String driverName = data.getStringExtra(KeyValue.KEY_NAME);
        String driverPhone = data.getStringExtra(KeyValue.KEY_PHONE);
        String vehicleNumber = data.getStringExtra(KeyValue.KEY_VEHICLE_NUMBER);
        mGoodsInfo.senttodetails = driverPhone;
        mObjectDetailClickItemView.setContent(driverName + "|" + driverPhone + "|" + vehicleNumber);
    }

    private void setSelectSalesMan(Intent data) {
        if (data != null) {
            Bundle bundle = data.getExtras();
            if (bundle != null && !bundle.isEmpty()) {
                String name = bundle.getString(KeyValue.KEY_NAME);
                String phone = bundle.getString(KeyValue.KEY_PHONE);
                String id = bundle.getString(KeyValue.KEY_ID);
                mSalesManListClickItemView.setContent(name + "(" + phone + ")");
                mGoodsInfo.salesmanuserid = id;

                mDestinationUserInputItemView.setContent(name);
                mDestinationPhoneInputItemView.setContent(phone);
            }
        }
    }

    @OnClick(R.id.activity_lite_deliver_goods_goodsTypeClickItemView)
    public void goodsType() {
        if (mGoodsTypeSelectDialog == null) {
            requestGoodsType();
        } else {
            mGoodsTypeSelectDialog.show();
        }

    }

    @OnClick(R.id.activity_lite_deliver_goods_cargoRightsClickItemView)
    public void cargoRights() {
        if (mCargoRightsSelectDialog == null) {
            requestCargoRights();
        } else {
            mCargoRightsSelectDialog.show();
        }

    }

    @OnClick(R.id.activity_lite_deliver_goods_belongAreaClickItemView)
    public void belongArea() {
        if (mBelongAreaSelectDialog == null) {
            mBelongAreaSelectDialog = new SelectDialog(getContext());
            mBelongAreaSelectDialog.setTitle("请选择所属区域");
            mBelongAreaSelectDialog.setList(getBelongAreaList());
            mBelongAreaSelectDialog.setOnSelectItemClickLister(new SelectDialog.OnSelectItemClickListener<SelectItemInfo>() {
                @Override
                public void onItemClick(SelectItemInfo item, int position) {
                    mBelongAreaClickItemView.setContent(item.getSelectItemText());
                    mGoodsInfo.belongarea = item.getSelectItemTextValue();
                    LogUtil.print("所属区域：" + item.getSelectItemText() + "--" + mGoodsInfo.belongarea);
                }
            });
        }
        mBelongAreaSelectDialog.show();
    }

    private List<SelectItemInfo> getBelongAreaList() {
        List<SelectItemInfo> list = new ArrayList<>();
        SelectItemInfo itemInfo;

        itemInfo = new SelectItemInfo();
        itemInfo.content = "天津";
        itemInfo.value = "2";
        list.add(itemInfo);

        itemInfo = new SelectItemInfo();
        itemInfo.content = "河北";
        itemInfo.value = "1";
        list.add(itemInfo);

        return list;
    }

    //货权列表
    private void requestCargoRights() {
        getPresenter().requestCargoRights();
    }

    private void showCargoRightsDialog(List<DictionaryInfo> dictionaryInfoList) {
        mCargoRightsSelectDialog = new SelectDialog<DictionaryInfo>(this);
        mCargoRightsSelectDialog.setTitle("请选择货权");
        mCargoRightsSelectDialog.setList(dictionaryInfoList);
        mCargoRightsSelectDialog.show();

        mCargoRightsSelectDialog.setOnSelectItemClickLister(new SelectDialog.OnSelectItemClickListener<DictionaryInfo>() {
            @Override
            public void onItemClick(DictionaryInfo iSelectViewItem, int position) {
                mCargoRightsClickItemView.setContent(iSelectViewItem.getSelectItemText());
                mGoodsInfo.customerno = iSelectViewItem.getSelectItemTextValue();
                mGoodsInfo.hq=iSelectViewItem.getSelectItemText();
                clearSelectDispatcher();
                requestDispatcherList();
                LogUtil.print("SelectedCargoRight", iSelectViewItem.getSelectItemText() + "----" + iSelectViewItem.getSelectItemTextValue());
            }
        });
    }

    private void clearSelectDispatcher() {
        mDispatcherClickItemView.setContent("");
        mGoodsInfo.dispatcheruserid = "";
    }

    private void requestGoodsType() {
        getPresenter().requestGoodsType();
    }

    private void showGoodsTypeDialog(List<DictionaryInfo> dictionaryInfoList) {
        mGoodsTypeSelectDialog = new SelectDialog<DictionaryInfo>(this);
        mGoodsTypeSelectDialog.setTitle("请选择货物类型");
        mGoodsTypeSelectDialog.setList(dictionaryInfoList);
        mGoodsTypeSelectDialog.show();

        mGoodsTypeSelectDialog.setOnSelectItemClickLister(new SelectDialog.OnSelectItemClickListener<DictionaryInfo>() {
            @Override
            public void onItemClick(DictionaryInfo iSelectViewItem, int position) {
                mGoodsTypeClickItemView.setContent(iSelectViewItem.getSelectItemText());
                mGoodsInfo.goodstype = iSelectViewItem.getSelectItemTextValue();
            }
        });
    }

    @OnClick(R.id.activity_lite_deliver_goods_vehicleLimitClickItemView)
    public void vehicleLimit() {
        if (mVehicleLimitSelectDialog == null) {
            requestVehicleLimit();
        } else {
            mVehicleLimitSelectDialog.show();
        }

    }

    private void requestVehicleLimit() {
        getPresenter().requestVehicleLimit();
    }

    private void showVehicleLimitInfoDialog(List<VehicleLimitInfo> vehicleLimitInfoList) {
        mVehicleLimitSelectDialog = new SelectDialog<VehicleLimitInfo>(this);
        mVehicleLimitSelectDialog.setTitle("请选择车长吨位");
        mVehicleLimitSelectDialog.setList(vehicleLimitInfoList);
        mVehicleLimitSelectDialog.show();

        mVehicleLimitSelectDialog.setOnSelectItemClickLister(new SelectDialog.OnSelectItemClickListener<VehicleLimitInfo>() {
            @Override
            public void onItemClick(VehicleLimitInfo vehicleLimitInfo, int position) {
                if (vehicleLimitInfo == null) return;

                mGoodsInfo.vehiclelengthtype = vehicleLimitInfo.id;

                mVehicleLimitClickItemView.setContent(vehicleLimitInfo.getSelectItemText());

            }
        });
    }

    @OnClick(R.id.activity_lite_deliver_goods_dispatcherClickItemView)
    public void dispatcherSelect() {
        if (mDispatcherListSelectDialog == null) {
            requestDispatcherList();
        } else {
            mDispatcherListSelectDialog.show();
        }

    }

    private void requestDispatcherList() {

        if (mGoodsInfo != null) {
            if (TextUtils.isEmpty(mGoodsInfo.customerno)) {
                showToast("请先选择货权");
                return;
            }
            Map<String, String> map = new HashMap<>();
            map.put("customerno", mGoodsInfo.customerno);
            getPresenter().requestDispatcherList(map, true);
        }


    }

    @OnClick(R.id.activity_lite_deliver_goods_deadlineTimeClickItemView)
    public void selectDeadlineTime() {
        hideKeyboard();
        if (mDeadlineSelectTimeDialog == null) {
            mDeadlineSelectTimeDialog = new SelectTimeDialog(this, new LoadingSelectTimeData());
            mDeadlineSelectTimeDialog.setOnSelectTimeConfirmClickListener(new SelectTimeDialog.OnSelectTimeConfirmClickListener() {
                @Override
                public void timeConfirm(String time) {
                    mDeadlineTimeClickItemView.setContent(time);
                }
            });
        }

        mDeadlineSelectTimeDialog.show();
    }

    @OnClick(R.id.activity_lite_deliver_goods_commitButton)
    public void commit() {

        LogUtil.print("mGoodsInfo.deliverprovince", mGoodsInfo.deliverprovince);
        LogUtil.print("mGoodsInfo.delivercity", mGoodsInfo.delivercity);
        LogUtil.print("mGoodsInfo.delivercounty", mGoodsInfo.delivercounty);
        LogUtil.print("mGoodsInfo.delivercitycode", mGoodsInfo.delivercitycode);
        LogUtil.print("mGoodsInfo.deliverParentCode", mGoodsInfo.deliverParentCode);

        String deliverUserName = mDeliverUserInputItemView.getContent();
        String deliverAddress = mDeliverAddressInputItemView.getContent();
        String deliverPhone = mDeliverPhoneInputItemView.getContent();

        mGoodsInfo.placeusername = deliverUserName;
        mGoodsInfo.placedetails = deliverAddress;
        mGoodsInfo.placetel = deliverPhone;

        mGoodsInfo.deliverdetails = deliverAddress;
        mGoodsInfo.deliverusername = deliverUserName;
        mGoodsInfo.delivertel = deliverPhone;

        boolean checkDeliverInfoResult = mDataProcess.checkDeliveryInfoPassOrNotFindCar(mGoodsInfo);
        if (!checkDeliverInfoResult) {
            return;
        }

        String destinationUserName = mDestinationUserInputItemView.getContent();
        String destinationAddress = mDestinationAddressInputItemView.getContent();
        String destinationPhone = mDestinationPhoneInputItemView.getContent();

        mGoodsInfo.destinationdetails = destinationAddress;
        mGoodsInfo.destinationusername = destinationUserName;
        mGoodsInfo.destinationtel = destinationPhone;

        boolean checkDestinationInfoResult = mDataProcess.checkDestinationInfoPassOrNotFindCar(mGoodsInfo);
        if (!checkDestinationInfoResult) {
            return;
        }

        if (TextUtils.isEmpty(mGoodsInfo.goodstype)) {
            showToast("请选择货物类型");
            return;
        }

        String remark = mRemarkInputItemView.getContent();
        mGoodsInfo.remarks = remark;

//        String goodsName = mGoodsNameInputItemView.getContent();
        String weight = mWeightInputItemView.getContent();
//        mGoodsInfo.goodsdescription = goodsName;

        if (null!=mGoodsInfo.weight&&!weight.equals(mGoodsInfo.weight)) {
            if (TextUtils.isEmpty(remark)){
                showToast("重量与原erp重量不同时，必须填写备注");
                return;
            }
        }

        mGoodsInfo.weight = weight;
        mGoodsInfo.quantity=weight;



//        String detachWeight = mDetachWeightInputItemView.getContent();
//        boolean checkDetachWeightResult = mDataProcess.checkGoodsDetachWeightIsRight(mGoodsInfo, detachWeight);
//        if (!checkDetachWeightResult) {
//            return;
//        }

//        String phone = mPhoneInputItemView.getContent();
//        mGoodsInfo.facetel = phone;
//        String price = mPriceInputItemView.getContent();
//        String maxPrice = mMaxPriceInputItemView.getContent();
//        String totalPrice = mTotalPriceInputItemView.getContent();
//        String allprice = inputv_zong_two.getContent();

//        mGoodsInfo.baseprice = price;
//        mGoodsInfo.bigprice = maxPrice;
//        if (!TextUtils.isEmpty(allprice)){
//            mGoodsInfo.totalprice = allprice;
//        }else {
//            mGoodsInfo.totalprice = totalPrice;
//        }

//        boolean checkInquiryStateResult = mDataProcess.checkLiteDeliverGoodsInquiryState(mGoodsInfo);
//        if (!checkInquiryStateResult) {//询价电话
//            return;
//        }


        String lendtime = mDeadlineTimeClickItemView.getContent();
        mGoodsInfo.lendtime = lendtime;
        mGoodsInfo.ordertruetime = lendtime;
        String deliverTime = mDeliverTimeInputItemView.getContent();
        mGoodsInfo.unloadearlhours = deliverTime;

//        boolean checkTimeResult = mDataProcess.checkLoadingAndUnLoadingTimeIsRight(mGoodsInfo);
//        if (!checkTimeResult) {//装卸车截止时间
//            return;
//        }


//        String goodsPrice = mGoodsPriceInputItemView.getContent();
//        if (TextUtils.isEmpty(goodsPrice)) {
//            showToast("请填写货物单价");
//            return;
//        }
//        mGoodsInfo.goodsunitprice = goodsPrice;

//        if (isShowBusinessView) {
//            String businessNumber = mBusinessNumberInputItemView.getContent();
//            if (TextUtils.isEmpty(businessNumber)) {
//                showToast("请填写业务单号");
//                return;
//            }
//            mGoodsInfo.businessno = businessNumber;
//            String cargoRights = mCargoRightsClickItemView.getContent();
//            if (TextUtils.isEmpty(cargoRights) || TextUtils.isEmpty(mGoodsInfo.customerno)) {
//                showToast("请选择货权");
//                return;
//            }
//            mGoodsInfo.salesmanuserid = SharedPreferenceManager.getInstance().getConsignorId();
//
//            String dispatcher = mDispatcherClickItemView.getContent();
//            if (TextUtils.isEmpty(dispatcher) || TextUtils.isEmpty(mGoodsInfo.dispatcheruserid)) {
//                showToast("请选择调度员");
//                return;
//            }
//        } else {
//            mGoodsInfo.dispatcheruserid = SharedPreferenceManager.getInstance().getConsignorId();
//        }
//
//        if (isShowSalesManView) {
//            String salesMan = mSalesManListClickItemView.getContent();
//            if (TextUtils.isEmpty(salesMan) || TextUtils.isEmpty(mGoodsInfo.salesmanuserid)) {
//                showToast("请选择销售员");
//                return;
//            }
//        }


        String cargoRights = mCargoRightsClickItemView.getContent();
        if (TextUtils.isEmpty(cargoRights) || TextUtils.isEmpty(mGoodsInfo.customerno)) {
            showToast("请选择货权");
            return;
        }
        mGoodsInfo.salesmanuserid = SharedPreferenceManager.getInstance().getConsignorId();

        String dispatcher = mDispatcherClickItemView.getContent();
        if (TextUtils.isEmpty(dispatcher) || TextUtils.isEmpty(mGoodsInfo.dispatcheruserid)) {
            showToast("请选择调度员");
            return;
        }

//        if (!TextUtils.isEmpty(mGoodsInfo.sentto) && mGoodsInfo.sentto.equals("02")) {
//            if (TextUtils.isEmpty(mGoodsInfo.senttodetails)) {
//                showToast("发送对象明细不能为空");
//                return;
//            }
//        } else {
//            mGoodsInfo.senttodetails = "";
//        }



        mGoodsInfo.sendordertime = DateUtil.getStandardTime(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss");

        //开发票
//        if (isFaPiao){
            mGoodsInfo.isinvoice="0";
//        }else {
//            mGoodsInfo.isinvoice="1";
//
//        }


        if (isFaPiaoTuiHuan){
            mGoodsInfo.isrefund="1";
        }else {
            mGoodsInfo.isrefund="0";
        }

        mGoodsInfo.depositamount="";


        mGoodsInfo.status="0";
        mGoodsInfo.verifymessage="";//审核意见


//        LogUtil.print(JsonUtil.toJson(mGoodsInfo));
//        if (isFaPiao){
//            String num = et_fapiao_num.getText().toString();
//            //不开发票
//            if (TextUtils.isEmpty(num)){
//                showToast("请输入订金金额");
//            }else {
//                mGoodsInfo.depositamount=num;
//                getPresenter().requestPublishLiteSourceBuKai(mGoodsInfo);
//            }
//
//        }else {
//            //开发票，不用订金
//            getPresenter().requestPublishLiteSource(mGoodsInfo);
//
//        }


        getAlreadySendWeight(mGoodsInfo);

//        showBankCardDiaLog(mGoodsInfo);


    }




    @Override
    public void publicGoodsSuccess() {
        openActivity(DeliverGoodsSuccessActivity.class);
        finish();
    }

    @Override
    public void showGoodsTypeList(List<DictionaryInfo> dictionaryInfoList) {
        showGoodsTypeDialog(dictionaryInfoList);
    }

    @Override
    public void showCargoRightsList(List<DictionaryInfo> dictionaryInfoList) {
        showCargoRightsDialog(dictionaryInfoList);
    }

    @Override
    public void showVehicleLimitList(List<VehicleLimitInfo> vehicleLimitInfoList) {
        showVehicleLimitInfoDialog(vehicleLimitInfoList);
    }

    @Override
    public void showDispatcherList(List<DispatcherInfo> list) {
        showDispatcherDialog(list);
    }

    private void showDispatcherDialog(List<DispatcherInfo> list) {
        mDispatcherListSelectDialog = new SelectDialog<DispatcherInfo>(this);
        mDispatcherListSelectDialog.setTitle("请选择调度员");
        mDispatcherListSelectDialog.setList(list);
        mDispatcherListSelectDialog.setOnSelectItemClickLister(new SelectDialog.OnSelectItemClickListener<DispatcherInfo>() {
            @Override
            public void onItemClick(DispatcherInfo dispatcherInfo, int position) {
                if (dispatcherInfo == null) return;

                mGoodsInfo.dispatcheruserid = dispatcherInfo.id;

                mDispatcherClickItemView.setContent(dispatcherInfo.name);
                LogUtil.print("SelectedDispatcher", dispatcherInfo.name + "-----" + dispatcherInfo.id);

            }
        });
    }

    @OnClick(R.id.activity_lite_deliver_goods_salesManListClickItemView)
    public void selectSalesMan() {
        openActivityForResult(REQUEST_CODE_SALES_MAN, SalesManListActivity.class);


    }

    @OnClick(R.id.activity_lite_deliver_goods_sendObjectClickItemView)
    public void sendObject() {
        if (mSendObjectSelectDialog == null) {
            requestSentObject();
        } else {
            mSendObjectSelectDialog.show();
        }
    }

    private void requestSentObject() {
        Map<String, String> map = new HashMap<>();
        map.put("pid", "2759");
        new OrderModel().dictionaryModel(this, map, true, this.bindLifecycle(), new ObserverResponseListener<CommonResponse<List<DictionaryInfo>>>() {
            @Override
            public void onNext(CommonResponse<List<DictionaryInfo>> commonResponse) {
                if (!isFinishing() && !isDestroyed()) {
                    if (commonResponse.getCode() == 20000) {
                        List<DictionaryInfo> list = commonResponse.getData();
                        if (list != null && list.size() > 0) {
                            showSendObjectDialog(list);
                        } else {
                            showToast("未获取到发送对象信息");
                        }
                    } else {
                        showToast(commonResponse.getMsg());
                    }
                }
            }

            @Override
            public void onError(ExceptionHandle.ResponseThrowable e) {

                showToast(e.message);
            }
        });
    }

    private void showSendObjectDialog(List<DictionaryInfo> list) {
        mSendObjectSelectDialog = new SelectDialog<String>(this);
        mSendObjectSelectDialog.setTitle("请选择发送对象");
        mSendObjectSelectDialog.setList(list);
        mSendObjectSelectDialog.show();
        mSendObjectSelectDialog.setOnSelectItemClickLister(new SelectDialog.OnSelectItemClickListener<DictionaryInfo>() {
            @Override
            public void onItemClick(DictionaryInfo item, int position) {
                mSendObjectClickItemView.setContent(item.getSelectItemText());
                mGoodsInfo.sentto = item.getSelectItemTextValue();
                if (position == 2) {
                    mObjectDetailLinearLayout.setVisibility(View.VISIBLE);
                } else {
                    mObjectDetailLinearLayout.setVisibility(View.GONE);
                }
            }
        });
    }

    @OnClick(R.id.activity_lite_deliver_goods_objectDetailClickItemView)
    public void driverDetail() {
        openActivityForResult(REQUEST_CODE_DRIVER_DETAIL, DriverDetailListActivity.class);
    }

//    @Override
//    protected void onDestroy() {
//        super.onDestroy();
//        if (mVehicleLimitSelectDialog != null) {
//            mVehicleLimitSelectDialog.setOnSelectItemClickLister(null);
//            mVehicleLimitSelectDialog = null;
//        }
//        if (mCargoRightsSelectDialog != null) {
//            mCargoRightsSelectDialog.setOnSelectItemClickLister(null);
//            mCargoRightsSelectDialog = null;
//        }
//        if (mDispatcherListSelectDialog != null) {
//            mDispatcherListSelectDialog.setOnSelectItemClickLister(null);
//            mDispatcherListSelectDialog = null;
//        }
//    }



    //发票
//    private PopupWindow mFaPiaoPopWindow;
//    private boolean isFaPiao=false;//是否退还 false 没有订金  true有订金
//    private void popWindow() {
//        //利用 LayoutInflater获取 R.layout.activity_popwindow 对应的 View
//        View contentView = LayoutInflater.from(this).inflate(R.layout.pop_fapiao, null);
//        mFaPiaoPopWindow = new PopupWindow(contentView);
//
//        /*
//         * 设置窗体的长和宽
//         * 代码强制设置 PopupWindow的 Height、Width(否则无法显示出来)
//         * popupWindow的宽和高, 以这里代码设置的为准
//         * */
//        mFaPiaoPopWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
//        mFaPiaoPopWindow.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
//        //充满
////        mPopWindow.setWidth(ViewGroup.LayoutParams.FILL_PARENT);
////        mPopWindow.setHeight(ViewGroup.LayoutParams.FILL_PARENT);
//
//        //设置动画所对应的style
////        mPopWindow.setAnimationStyle(R.style.contextMenuAnim);
//        /*
//         * 外部点击, 隐藏窗体的功能(三种方法)
//         * */
//        //1. 设置再次点击控件的时候，关闭窗口，不重新打开
//        mFaPiaoPopWindow.setFocusable(true);
//        //2.
////        mPopWindow.setOutsideTouchable(true);
//        //3.
////        ColorDrawable dw = new ColorDrawable(0x00000000);
////        mPopWindow.setBackgroundDrawable(dw);
//
//
//        /*
//         * 设置窗体在控件的相对位置
//         * */
//        // 显示在某个控件的正左下方，无偏移
////        mFaPiaoPopWindow.showAsDropDown(tv);
//        // 相对某个控件的位置，有偏移，xoff为 X轴的偏移量，yoff为 Y轴的偏移量
////        mPopWindow.showAsDropDown(tv, 0, 0);
//        //相对于父控件的位置（例如正中央Gravity.CENTER，下方Gravity.BOTTOM等），可以设置偏移或无偏移
//        mFaPiaoPopWindow.showAtLocation(mDetachWeightLinearLayout, Gravity.BOTTOM, 0, 0);
//
//
//        ImageView iv_empty= contentView.findViewById(R.id.iv_empty);
//        ImageView iv_bukai= contentView.findViewById(R.id.iv_bukai);
//        ImageView iv_kai= contentView.findViewById(R.id.iv_kai);
//        LinearLayout ll_bukai_body = contentView.findViewById(R.id.ll_bukai_body);
//        ll_bukai_body.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                isFaPiao=true;
//                iv_bukai.setImageResource(R.mipmap.icon_selected);
//                iv_kai.setImageResource(R.mipmap.icon_unselected);
//                mBelongAreaClickItemView.setContent("河北");
//                mGoodsInfo.belongarea = "1";
//            }
//        });
//        LinearLayout ll_zhuanpiao_body = contentView.findViewById(R.id.ll_zhuanpiao_body);
//        ll_zhuanpiao_body.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                isFaPiao=false;
//                iv_bukai.setImageResource(R.mipmap.icon_unselected);
//                iv_kai.setImageResource(R.mipmap.icon_selected);
//
//                mBelongAreaClickItemView.setContent("天津");
//                mGoodsInfo.belongarea = "2";
//            }
//        });
//
//        TextView tv_tijiao = contentView.findViewById(R.id.tv_tijiao);
//        tv_tijiao.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (isFaPiao){
//                    fapiao_jine_body.setVisibility(View.VISIBLE);
//                    fapioa_item_contentEditText.setText("不开发票");
//                }else {
//                    fapiao_jine_body.setVisibility(View.GONE);
//                    fapioa_item_contentEditText.setText("专票");
//
//                }
//                mFaPiaoPopWindow.dismiss();
//
//            }
//        });
//
//        iv_empty.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                mFaPiaoPopWindow.dismiss();
//            }
//        });
//
//    }

    //总价逆推单价
    private String getDJPrice() {
        //数据失精处理
        String price = TextUtils.isEmpty(allPrice) ? "0" : allPrice;
        String goodsWeight = TextUtils.isEmpty(mGoodsWeight) ? "0" : mGoodsWeight;
        String totalPrice;
        if (!"0".equals(goodsWeight)) {

//            BigDecimal b1 = new BigDecimal(allPrice);
//            BigDecimal b2 = new BigDecimal(mGoodsWeight);
//             b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).doubleValue();

             totalPrice = new BigDecimal(price).divide(new BigDecimal(goodsWeight), 2, BigDecimal.ROUND_CEILING).doubleValue() + "";
        }else {
             totalPrice ="0";
        }
//        String totalPrice = new BigDecimal(price).multiply(new BigDecimal(goodsWeight)).toString();//两个数字相乘（加减乘除的单词就是方法）
        return CommonUtil.keepTwoDecimal(totalPrice);
    }



    private Runnable runnableDan;
    private Runnable runnableZong;

    private void setJiaGe(){
        handler = new Handler();

         runnableDan = new Runnable() {
            @Override
            public void run() {
                // 这个是循环 间隔3s弹一次Toast
//                handler.postDelayed(this, 3 *1000);
//                Toast.makeText(this, "延时5s", Toast.LENGTH_SHORT).show();

//                    mMaxPriceInputItemView.setContent(mPrice);
//                    mTotalPriceInputItemView.setContent(getTotalPrice());

                xunHuanZong=true;
            }
        };

        runnableZong = new Runnable() {
            @Override
            public void run() {
                // 这个是循环 间隔3s弹一次Toast
//                handler.postDelayed(this, 3 *1000);
//                Toast.makeText(this, "延时5s", Toast.LENGTH_SHORT).show();

//                String djPrice = getDJPrice();
//                mPriceInputItemView.setContent(djPrice);
//                mMaxPriceInputItemView.setContent(djPrice);

                xunHuanDan=true;
            }
        };

    }


    //初始化先
    private Handler handler;

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //在页面结束时 清空队列消息
        if (handler != null) {
            handler.removeCallbacksAndMessages(null);
            handler = null;
        }
        //地址选择地图监听
//        mSuggestionSearch.destroy();
        try {
            EventBus.getDefault().unregister(this);
        }catch (Exception e){
            LogUtil.print(e.toString());
        }

    }

    private void goSelectDress(int type) {
        Bundle bundle = new Bundle();
        bundle.putInt(KeyValue.KEY_TYPE, type);
        ApplicationUtil.openActivity(SelectDressActivity.class, bundle);//SelectDressXuanActivity
    }


    private PopupWindow dressPopup;
    private PopDressListAdapter dressListAdapter;
    private List<SuggestionResult.SuggestionInfo> allSuggestions;
    private boolean openPop=true;
    private int whitchSet=1;

    private void initPopupWindow() {
        // 将布局文件转换成View对象，popupview 内容视图
        View  mPopView = getLayoutInflater().inflate(R.layout.pop_dress_layout, null);
        // 将转换的View放置到 新建一个popuwindow对象中
        dressPopup = new PopupWindow(mPopView,
                LinearLayout.LayoutParams.MATCH_PARENT,
                400);
        // 点击popuwindow外让其消失
        dressPopup.setOutsideTouchable(true);
        // mpopupWindow.setBackgroundDrawable(background)

        RecyclerView lv_dress = mPopView.findViewById(R.id.lv_dress);

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        lv_dress.setLayoutManager(linearLayoutManager);
        dressListAdapter = new PopDressListAdapter(this);
        lv_dress.setAdapter(dressListAdapter);

        if (allSuggestions != null ) {//&& mConsignorList.size() > 0
            dressListAdapter.addAll(allSuggestions);
        }

        dressListAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                try {
                    openPop=false;
                    Object object = dressListAdapter.getAllData().get(position);
                    if (object != null && object instanceof SuggestionResult.SuggestionInfo) {
                        SuggestionResult.SuggestionInfo info = (SuggestionResult.SuggestionInfo) object;
                        if (1==whitchSet) {
                            mDeliverAddressInputItemView.setContent(info.getKey());
                        }else {
                            mDestinationAddressInputItemView.setContent(info.getKey());
                        }
                        dressPopup.dismiss();
                    }
                }catch (Exception e){
                    LogUtil.print(e.toString());
                }

            }
        });

    }


    private SourcePathInfo pathInfoZhuang;
    private SourcePathInfo pathInfoXie;
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void getSelectDress(SourcePathInfo pathInfo){
        int whitchSet = pathInfo.whitchSet;
        if (2==whitchSet){
            setSelectPathInfo(KeyValue.RESULT_DELIVER, pathInfo, false);
            zhuang_dress_two.setContent(pathInfo.shuAddress);
            zhuang_dizhi_two.setContent(pathInfo.address);
            mDeliverCitySearchView.setContent(pathInfo.address);
            mDeliverAddressInputItemView.setContent(pathInfo.shuAddress);
//            setSelectPathHistory(mDeliverCitySearchView, mDeliverAddressInputItemView, mDeliverUserInputItemView, mDeliverPhoneInputItemView, pathInfo);
            pathInfoZhuang=pathInfo;
        }else {
            setSelectPathInfo(KeyValue.RESULT_DESTINATION, pathInfo, false);
            xie_dress_two.setContent(pathInfo.shuAddress);
            xie_dizhi_two.setContent(pathInfo.address);
            mDestinationCitySearchView.setContent(pathInfo.address);
            mDestinationAddressInputItemView.setContent(pathInfo.shuAddress);
            pathInfoXie=pathInfo;
        }

        if (null!=pathInfo.latLng) {
            calculateDistance();
        }else {
            String dress = pathInfo.shuAddress + pathInfo.address;
            String placecity = pathInfo.placecity;
            getSaveJingWei(dress,placecity,whitchSet);
        }
    }

    //计算距离
    private void calculateDistance(){
        ServiceSettings.updatePrivacyShow(this,true,true);
        ServiceSettings.updatePrivacyAgree(this,true);
        itv_juli.setVisibility(View.GONE);
        if (null!=pathInfoZhuang&&null!=pathInfoXie&&null!=pathInfoZhuang.latLng&&null!=pathInfoXie.latLng){

            try {
                DistanceSearch distanceSearch = new DistanceSearch(this);
                distanceSearch.setDistanceSearchListener(new DistanceSearch.OnDistanceSearchListener() {
                    @Override
                    public void onDistanceSearched(DistanceResult distanceResult, int i) {
                        try {
                            List<DistanceItem> distanceResults = distanceResult.getDistanceResults();
                            if (distanceResults.size()>0) {
                                DistanceItem distanceItem = distanceResults.get(0);
                                float distance = distanceItem.getDistance();
                                int mi = (int) (distance / 1000);
                                mGoodsInfo.senddistance = mi + "";
                                mGoodsInfo.estimatedmileage = mi + "";
                                itv_juli.setContent(mi + "公里");
                                itv_juli.setVisibility(View.VISIBLE);
                            }else {
                                ToastUtil.showShortToast("无法计算两地距离，请检查装货地是否有误");
                            }
                        }catch (Exception e){
                            ToastUtil.showShortToast("无法计算两地距离，请检查装货地是否有误");
                            LogUtil.print("fei",e.toString());
                        }

                    }
                });


                LatLonPoint start = new LatLonPoint(pathInfoZhuang.latLng.latitude,pathInfoZhuang.latLng.longitude);
                LatLonPoint end = new LatLonPoint(pathInfoXie.latLng.latitude,pathInfoXie.latLng.longitude);

                //设置起点和终点，其中起点支持多个
                List<LatLonPoint> latLonPoints = new ArrayList<LatLonPoint>();
                latLonPoints.add(start);
//                latLonPoints.add(end);
//                latLonPoints.add(start2);
//                latLonPoints.add(start3);

                DistanceSearch.DistanceQuery distanceQuery=new DistanceSearch.DistanceQuery();

                distanceQuery.setOrigins(latLonPoints);
                distanceQuery.setDestination(end);
                //设置测量方式，支持直线和驾车
                distanceQuery.setType(DistanceSearch.TYPE_DRIVING_DISTANCE);

                distanceSearch.calculateRouteDistanceAsyn(distanceQuery);
            } catch (AMapException e) {
                e.printStackTrace();
            }


//            double distance = DistanceUtil.getDistance(pathInfoZhuang.latLng, pathInfoXie.latLng);
//            String format;
//            if (0==distance){
//                 format = "0";
//                mGoodsInfo.senddistance= "0";
//                mGoodsInfo.estimatedmileage= "0";
//            }else {
//                DecimalFormat df = new DecimalFormat("#.00");
////            if (1000<distance){
//                double num = distance / 1000;
//                format = df.format(num);
//
//                int i=(int) num;
//                mGoodsInfo.senddistance=i+"";
//                mGoodsInfo.estimatedmileage=i+"";
//            }
//            itv_juli.setContent(format+"公里");
////            }else {
////                String format = df.format(distance);
////                itv_juli.setContent(format+"米");
////            }
//            itv_juli.setVisibility(View.VISIBLE);


        }
    }



    private GeocodeSearch  geocoderSearch;
    private int whereJiSuan;
    //逆地理编码
    private void getSaveJingWei(String dress,String city,int resultCode){
        ServiceSettings.updatePrivacyShow(this,true,true);
        ServiceSettings.updatePrivacyAgree(this,true);
        whereJiSuan=resultCode;
        try {
            if (null==geocoderSearch) {
                geocoderSearch = new GeocodeSearch(this);
                geocoderSearch.setOnGeocodeSearchListener(new GeocodeSearch.OnGeocodeSearchListener() {
                    @Override
                    public void onRegeocodeSearched(RegeocodeResult regeocodeResult, int i) {

                    }

                    @Override
                    public void onGeocodeSearched(GeocodeResult geocodeResult, int i) {
                        //解析result获取坐标信息
                        List<GeocodeAddress> geocodeAddressList = geocodeResult.getGeocodeAddressList();
                        if (geocodeAddressList.size()>0){
                            GeocodeAddress geocodeAddress = geocodeAddressList.get(0);
                            LatLonPoint latLonPoint = geocodeAddress.getLatLonPoint();

                            if (whereJiSuan == KeyValue.RESULT_DELIVER) {//装货
                                LatLng latLng=new LatLng(latLonPoint.getLatitude(),latLonPoint.getLongitude());
                                pathInfoZhuang.latLng=latLng;
                                mGoodsInfo.deliverlon=latLonPoint.getLongitude()+"";
                                mGoodsInfo.deliverlat=latLonPoint.getLatitude()+"";

                            } else if (whereJiSuan == KeyValue.RESULT_DESTINATION) {//卸货
                                LatLng latLng=new LatLng(latLonPoint.getLatitude(),latLonPoint.getLongitude());
                                pathInfoXie.latLng=latLng;
                                mGoodsInfo.destinationlon=latLonPoint.getLongitude()+"";
                                mGoodsInfo.destinationlat=latLonPoint.getLatitude()+"";

                            }

                            calculateDistance();
                        }



                    }
                });
            }

            // name表示地址，第二个参数表示查询城市，中文或者中文全拼，citycode、adcode "010"
            GeocodeQuery query = new GeocodeQuery(dress, city);
            geocoderSearch.getFromLocationNameAsyn(query);
        } catch (AMapException e) {
            e.printStackTrace();
        }

    }




    //逆地理编码
    private void setZhuanhuo(String dress,String city){
        ServiceSettings.updatePrivacyShow(this,true,true);
        ServiceSettings.updatePrivacyAgree(this,true);
        try {

                GeocodeSearch  geocoderSearch = new GeocodeSearch(this);
                geocoderSearch.setOnGeocodeSearchListener(new GeocodeSearch.OnGeocodeSearchListener() {
                    @Override
                    public void onRegeocodeSearched(RegeocodeResult regeocodeResult, int i) {

                    }

                    @Override
                    public void onGeocodeSearched(GeocodeResult geocodeResult, int i) {
                        if (null != geocodeResult) {
                            //解析result获取坐标信息
                            List<GeocodeAddress> geocodeAddressList = geocodeResult.getGeocodeAddressList();
                            if (geocodeAddressList.size() > 0) {
                                GeocodeAddress geocodeAddress = geocodeAddressList.get(0);
                                LatLonPoint latLonPoint = geocodeAddress.getLatLonPoint();

//                            if (whereJiSuan == KeyValue.RESULT_DELIVER) {//装货
                                LatLng latLng = new LatLng(latLonPoint.getLatitude(), latLonPoint.getLongitude());
                                pathInfoZhuang.latLng = latLng;
//                            } else if (whereJiSuan == KeyValue.RESULT_DESTINATION) {//卸货
//                                LatLng latLng=new LatLng(latLonPoint.getLatitude(),latLonPoint.getLongitude());
//                                pathInfoXie.latLng=latLng;
//                            }

                                mGoodsInfo.deliverlon = latLonPoint.getLongitude() + "";
                                mGoodsInfo.deliverlat = latLonPoint.getLatitude() + "";

                                //填入装货地
//                            SourcePathInfo pathInfo=new SourcePathInfo();
                                pathInfoZhuang.placeprovince = geocodeAddress.getProvince();
                                pathInfoZhuang.placecity = geocodeAddress.getCity();
                                pathInfoZhuang.placecounty = geocodeAddress.getDistrict();
                                pathInfoZhuang.placecitycode = geocodeAddress.getAdcode();
                                pathInfoZhuang.placeparentcode = geocodeAddress.getAdcode();
//                                pathInfoZhuang.shuAddress = dress;
//                                pathInfoZhuang.shuAddress = mGoodsInfo.housename;
                                pathInfoZhuang.shuAddress = geocodeAddress.getFormatAddress();



//                            pathInfoZhuang=pathInfo;

                                mDeliverAddressInputItemView.setContent(pathInfoZhuang.shuAddress);

                                pathInfoZhuang.address = geocodeAddress.getProvince() + " " + geocodeAddress.getCity() + " " + geocodeAddress.getDistrict();

                                setSelectPathInfo(KeyValue.RESULT_DELIVER, pathInfoZhuang, false);
                                zhuang_dress_two.setContent(pathInfoZhuang.shuAddress);
                                zhuang_dizhi_two.setContent(pathInfoZhuang.address);
                                mDeliverCitySearchView.setContent(pathInfoZhuang.address);


                                whereJiSuan = KeyValue.RESULT_DELIVER;
                                calculateDistance();
                            }


                        }else {


//                            pathInfoZhuang.shuAddress = mGoodsInfo.housename;
                            pathInfoZhuang.shuAddress = "";
                            zhuang_dress_two.setContent(pathInfoZhuang.shuAddress);
                            mDeliverAddressInputItemView.setContent(pathInfoZhuang.shuAddress);

//                            String replace = dress.replace("；", ";");
//                            String[] adressSplit = replace.split(";");
//                            mDeliverAddressInputItemView.setContent(adressSplit[0]);//pathInfoZhuang.shuAddress
//                            mDeliverAddressInputItemView.setContent(pathInfoZhuang.shuAddress);
                        }
                    }
                });


            // name表示地址，第二个参数表示查询城市，中文或者中文全拼，citycode、adcode "010"
            GeocodeQuery query = new GeocodeQuery(dress, city);
            geocoderSearch.getFromLocationNameAsyn(query);
        } catch (AMapException e) {
            e.printStackTrace();
        }

    }


    private void sendFindCarList(GoodsInfo mGoodsInfo) {


        mModel.sendFindCarList(this, mGoodsInfo, true, bindLifecycle(), new ObserverResponseListener<CommonResponse>() {
            @Override
            public void onNext(CommonResponse commonResponse) {
               if (commonResponse.getCode() == 20000) {
                       publicGoodsSuccess();
               } else {
                      setMsg(commonResponse.getMsg());
               }


            }

            @Override
            public void onError(ExceptionHandle.ResponseThrowable e) {
               setMsg(e.message);
            }
        });

    }

    private void getLeiXingList(){
        Map<String, String> map = new HashMap<>();
        map.put("pid", "73");
        mModel.dictionaryModel(getContext(), map, true, bindLifecycle(), new ObserverResponseListener<CommonResponse<List<DictionaryInfo>>>() {
            @Override
            public void onNext(CommonResponse<List<DictionaryInfo>> commonResponse) {

                    if (commonResponse.getCode() == 20000) {
                        List<DictionaryInfo> dictionaryInfoList = commonResponse.getData();
                        if (dictionaryInfoList != null && dictionaryInfoList.size() > 0) {
                            DictionaryInfo dictionaryInfo = dictionaryInfoList.get(0);
                            mGoodsTypeClickItemView.setContent(dictionaryInfo.getSelectItemText());
                            mGoodsInfo.goodstype = dictionaryInfo.getSelectItemTextValue();
//                            showGoodsTypeList(dictionaryInfoList);
                        }
                    }
            }
            @Override
            public void onError(ExceptionHandle.ResponseThrowable e) {
                setMsg(e.message);
            }
        });
    }

    private void showBankCardDiaLog(GoodsInfo mGoodsInfo){
//        String msg="交货成功\n收货人电话:"+shouHuaoPhone;
        String content = mWeightInputItemView.getContent();
        String msg="确认信息";
        String message = "发货地："+mGoodsInfo.deliverprovince+mGoodsInfo.delivercity+mGoodsInfo.delivercounty+
                "\n目的地："+mGoodsInfo.destinationprovince+mGoodsInfo.destinationcity+mGoodsInfo.destinationcounty+
                "\n货权："+mGoodsInfo.hq+
                "\n总量："+content+"吨";
        new MaterialDialog.Builder(this)
//                .title("交货成功")
                .title(msg)
                .content(message)
                .positiveText("确认")//查看
                .onPositive(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
//                        showConfirmDialog();
                        sendFindCarList(mGoodsInfo);
                    }
                })
                .negativeText("修改")//返回首页
                .onNegative(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
//                        Intent intent=new Intent(OrderDeliveryActivity.this,ChangeBankCardActivity.class);
//                        startActivity(intent);
//                        showConfirmDialog();

                    }
                })
                .canceledOnTouchOutside(false)
                .cancelable(false)
                .show();
    }


    /**
     * 使用java正则表达式去掉多余的.与0
     * @param s
     * @return
     */
    private   String subZeroAndDot(String s){
        if(s.indexOf(".") > 0){
            s = s.replaceAll("0+?$", "");//去掉多余的0
            s = s.replaceAll("[.]$", "");//如最后一位是.则去掉
        }
        return s;
    }



    private void getAlreadySendWeight(GoodsInfo mGoodsInfo) {
        String weight = mWeightInputItemView.getContent();
        Map<String, String> map = new HashMap<>();
        map.put("id", "");
        map.put("code", mGoodsInfo.code);
        map.put("totalQuaity", erpWeight);
        map.put("quality", weight);
        mModel.getAlreadySendWeight(getContext(), map, true, bindLifecycle(), new ObserverResponseListener<CommonResponse<CommonResponse>>() {
            @Override
            public void onNext(CommonResponse<CommonResponse> commonResponse) {
                if (commonResponse.getCode() == 20000) {

                    showBankCardDiaLog(mGoodsInfo);

                }else {
//                    Toast.makeText(FindCarLiteDeliverActivity.this, commonResponse.getMsg(), Toast.LENGTH_LONG).show();
                    setMsg(commonResponse.getMsg());
//                    showChaoZhongDiaLog(commonResponse.getMsg());
                }
            }
            @Override
            public void onError(ExceptionHandle.ResponseThrowable e) {
                setMsg(e.message);
            }
        });

    }



    private void showChaoZhongDiaLog(String message){

//        String content = mWeightInputItemView.getContent();
        String msg="超出erp实际重量";
//        String message = "erp中总重量："+erpWeight+
//                "\n已发重量："+weight+
//                "\n可发重量："+mGoodsInfo.hq;
        new MaterialDialog.Builder(this)
//                .title("交货成功")
                .title(msg)
                .content(message)
                .positiveText("确认")//查看
                .onPositive(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
//                        showConfirmDialog();
                        sendFindCarList(mGoodsInfo);
                    }
                })
//                .negativeText("修改")//返回首页
//                .onNegative(new MaterialDialog.SingleButtonCallback() {
//                    @Override
//                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
////                        Intent intent=new Intent(OrderDeliveryActivity.this,ChangeBankCardActivity.class);
////                        startActivity(intent);
////                        showConfirmDialog();
//
//                    }
//                })
                .canceledOnTouchOutside(false)
                .cancelable(false)
                .show();
    }






}
